__author__ = 'hl'
import pickle

class OperateCache:
    def __init__(self,filePath,mode):
        try:
            self.__file = open(filePath,mode)
        except:
            print 'opening file failed under this path:%s'%(filePath,)+',please review parameters passed'

    def Save(self,obj):
        try:
            pickle.dump(obj,self.__file)
            self.__file.flush()
        except:
            print 'class: OperateCache\n'\
                  'method: Save\n'\
                  'saving cache failed'
            return
        print 'saving cache successed'

    def Get(self):
        try:
            return pickle.load(self.__file)
        except:
            print 'class: OperateCache\n'\
                  'method: Get\n'\
                  'parsing cache failed'
            return  None


    def closeFile(self):
        try:
            self.__file.close()
        except:
            pass